package analysis.bean;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

public class BrowserDimension extends Unit {
    public int id;
    public String browserName;
    public String browserVersion;

    public BrowserDimension(){
    }

    public BrowserDimension(String browserName, String browserVersion) {
        this.browserName = browserName;
        this.browserVersion = browserVersion;
    }

    public BrowserDimension(int id,String browserName, String browserVersion) {
        this(browserName,browserVersion);
        this.id = id;
    }

    @Override
    public int compareTo(Unit o) {
        BrowserDimension other = (BrowserDimension)o;
        if(this.id!=other.id)
        {
            return this.id-other.id;
        }else{
            if(!this.browserName.equals(other.browserName))
                return this.browserName.compareTo(other.browserName);
            else{
                if(!this.browserVersion.equals(other.browserVersion))
                    return this.browserVersion.compareTo(other.browserVersion);
                else
                    return 0;
            }
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(this.id);
        dataOutput.writeUTF(this.browserName);
        dataOutput.writeUTF(this.browserVersion);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.id = dataInput.readInt();
        this.browserName = dataInput.readUTF();
        this.browserVersion = dataInput.readUTF();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BrowserDimension that = (BrowserDimension) o;
        return id == that.id &&
                Objects.equals(browserName, that.browserName) &&
                Objects.equals(browserVersion, that.browserVersion);
    }

    @Override
    public int hashCode() {

        return Objects.hash(id, browserName, browserVersion);
    }
}
